package com.baosight.sczx.zm.cx.service;

import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.cp.ProducePlanCM;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.ck.domain.ZMCKRJGGL;
import com.baosight.sczx.zm.cp.domain.ZMCPProfessionalPlan;
import com.baosight.sczx.zm.cx.domain.ZMCXPerson;

/**
 * 
 * <p>Title: ServiceZMCK35.java</p>
 * <p>Description: 入井管轨缆接地装置检查记录 </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2016年9月18日 上午10:42:15  郭淑芳  Create
 *</pre>
 */
public class ServiceZMCX01 extends ServiceEPBase {
	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始进入方法</p>
	 * <p>return value: ServiceZMCK35</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:42:30 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");// 如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}

	/**
	 * 
	 * <p>Function: query</p>
	 * <p>Description: 查询方法</p>
	 * <p>return value: ServiceZMCK35</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:42:39 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		
//		String id= UserSession.getInSessionProperty("miningCode").toString() ;
				
		if(null != UserSession.getInSessionProperty("miningCode") && !("").equals(UserSession.getInSessionProperty("miningCode"))) 
		{
			StaticTools.setQueryParameters(inInfo, "fdMiningId", UserSession.getInSessionProperty("miningCode").toString(), true);
		}
		EiInfo outInfo = super.query(inInfo, "ZMCXPerson.query", new ZMCXPerson());
		return outInfo;
	}

	
	/**
	 * 
	 * <p>Function: insert</p>
	 * <p>Description: 新增方法</p>
	 * <p>return value: ServiceZMCK35</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:42:51 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {
		EiInfo out = new EiInfo();
		ZMCXPerson _dom = new ZMCXPerson();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			_dom.setfdMiningId(UserSession.getInSessionProperty("miningCode").toString());
			
			_dom.setFdKeyId(TablePk.getInstance().getNextValue("T_CX_PERSON"));

			this.dao.insert("ZMCXPerson.insert", _dom);
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
	}

	/**
	 * 
	 * <p>Function: update</p>
	 * <p>Description: 修改方法</p>
	 * <p>return value: ServiceZMCK35</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:43:40 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo out = new EiInfo();
		ZMCXPerson _dom = new ZMCXPerson();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			_dom.setfdMiningId(UserSession.getInSessionProperty("miningCode").toString());
			this.dao.update("ZMCXPerson.update", _dom);
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
	}

	/**
	 * 
	 * <p>Function: delete</p>
	 * <p>Description: 删除方法</p>
	 * <p>return value: ServiceZMCK35</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月18日上午10:44:18 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		EiInfo out = new EiInfo();
		ZMCXPerson _dom = new ZMCXPerson();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));

			this.dao.delete("ZMCXPerson.delete", _dom);
		}
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
		
		
		
//		return super.delete(inInfo,"ZMCXPerson.delete");
		
//			EiInfo out = new EiInfo();
//			super.delete(inInfo, "ZMCXPerson.delete");
//			out.setStatus(1);
//			out=this.query(inInfo);
//			out.setMsg("删除操作成功");
//			return out;
		}

}
